﻿#region Using Directives

using System;
using System.Collections.Generic;
using System.Xml.Serialization;

#endregion Using Directives

namespace StooRob.SharePoint.ContentUpdater
{
    [Serializable()]
    [XmlTypeAttribute(AnonymousType = true)]
    public class ContentUpdateActions
    {
        List<Action> _actions;

        [XmlElement("Action")]
        public List<Action> Actions
        {
            get { return _actions; }
            set { _actions = value; }
        }
    }

    [Serializable()]
    [XmlTypeAttribute(AnonymousType = true)]
    [XmlRootAttribute(Namespace = "", IsNullable = false)]
    public class Action
    {
        List<ContentUpdate> _contentUpdate;
        string _url;
        string _site;
        string _page;

        [XmlElementAttribute("ContentUpdate")]
        public List<ContentUpdate> ContentUpdates
        {
            get
            {
                return this._contentUpdate;
            }
            set
            {
                this._contentUpdate = value;
            }
        }

        [XmlAttributeAttribute()]
        public string Url
        {
            get
            {
                return this._url;
            }
            set
            {
                if (!value.EndsWith("/"))
                    value += "/";
                this._url = value;
            }
        }

        [XmlAttributeAttribute()]
        public string Site
        {
            get
            {
                return this._site;
            }
            set
            {
                if (value.StartsWith("/"))
                    value = value.Substring(1);
                if (value.EndsWith("/"))
                    value = value.Substring(0, value.Length-1);
                this._site = value;
            }
        }

        [XmlAttributeAttribute()]
        public string Page
        {
            get
            {
                return this._page;
            }
            set
            {
                if (value.StartsWith("/"))
                    value = value.Substring(1);
                this._page = value;
            }
        }
    }
   
    [Serializable()]
    [XmlTypeAttribute(AnonymousType = true)]
    [XmlRootAttribute(Namespace = "", IsNullable = false)]
    public class ContentUpdate
    {
        private List<PropertyUpdate> _propertyUpdate;
        private UpdateTypes _updateType;
        private string _webPartNamespace;
        private string _webPartZoneTitle;
        private string _value;
        private string _webPartTitle;
        private int _webPartZoneIndex;

        [XmlElementAttribute("PropertyUpdate")]
        public List<PropertyUpdate> PropertyUpdates
        {
            get
            {
                return this._propertyUpdate;
            }
            set
            {
                this._propertyUpdate = value;
            }
        }

        [XmlAttributeAttribute()]
        public UpdateTypes UpdateType
        {
            get
            {
                return this._updateType;
            }
            set
            {
                this._updateType = value;
            }
        }

        [XmlAttributeAttribute()]
        public string WebPartNamespace
        {
            get
            {
                return this._webPartNamespace;
            }
            set
            {
                this._webPartNamespace = value;
            }
        }

        [XmlAttributeAttribute()]
        public string WebPartZoneTitle
        {
            get
            {
                return this._webPartZoneTitle;
            }
            set
            {
                this._webPartZoneTitle = value;
            }
        }

        [XmlAttributeAttribute()]
        public string WebPartTitle
        {
            get
            {
                return this._webPartTitle;
            }
            set
            {
                this._webPartTitle = value;
            }
        }

        [XmlAttributeAttribute()]
        public int WebPartZoneIndex
        {
            get
            {
                return this._webPartZoneIndex;
            }
            set
            {
                this._webPartZoneIndex = value;
            }
        }

        [XmlTextAttribute()]
        public string Value
        {
            get
            {
                return this._value;
            }
            set
            {
                this._value = value;
            }
        }
    }

    [Serializable()]
    [XmlTypeAttribute(AnonymousType = true)]
    [XmlRootAttribute(Namespace = "", IsNullable = false)]
    public class PropertyUpdate
    {
        private string _name;
        private string _value;

        [XmlAttributeAttribute()]
        public string Name
        {
            get
            {
                return this._name;
            }
            set
            {
                this._name = value;
            }
        }

        [XmlTextAttribute()]
        public string Value
        {
            get
            {
                return this._value;
            }
            set
            {
                this._value = value;
            }
        }
    }

    [SerializableAttribute()]
    public enum UpdateTypes
    {

        Add,
        Update,
        Remove,
    }
}
